package com.baturu.vin.benz.dal.dao;

import com.baturu.vin.benz.dto.BenzCarSystemDTO;
import com.baturu.vin.benz.dto.BenzEPCPartsInfoDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author jiangxinlei
 * @Time 2017/2/22.
 */
public interface BenzEPCPartsDAO {

    @Select({"<script>select distinct cbPartsCode,type,submods from bm_parts2_v",
            "where cbPartsCode in ",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "</script>"})
    List<BenzEPCPartsInfoDTO> getSubModsByCode(@Param("partsCodes") Collection<String> partsCodes);

    @Select({"select distinct partsCode,btrPartsName as partsName from benz_parts_mapping"})
    List<BenzCarSystemDTO> getCodesAndNames();

    @Select({"<script>select DISTINCT brand,carSystem from carsystem_chassis where chassis in",
            "<foreach item = 'chassis' index = 'index' collection = 'chassises' open = '(' separator=',' close=')'> ",
            "#{chassis}",
            "</foreach>",
            "</script>"})
    Set<BenzCarSystemDTO> findCarsInfos(@Param("chassises") Set<String> chassises);

    @Insert({"<script>insert into tmp_pp_parts_result(partsCode, partsName, carSystem,brand)" +
            "values " +
            "<foreach item = 'carsystemDTO' index ='index' collection = 'benzCarSystemDTOs' open = '' separator=',' close=''>" +
            "(#{carsystemDTO.partsCode},#{carsystemDTO.partsName},#{carsystemDTO.carSystem},#{carsystemDTO.brand})",
            "</foreach>" +
                    "</script>"})
    int insertCarsystems(@Param("benzCarSystemDTOs") Set<BenzCarSystemDTO> benzCarSystemDTOs);

}
